<?php

class event extends Model
{
	
	function getEventById($id)
	{
		$myevent = $this->db->getAll("SELECT event.name Event,
				event.date,
				event.starttime,
				event.endtime,
				event.event_id,
				event.description,
				event.venue,
				event.fee,
				organization.org_id,
				organization.name,
				organization.logo logo
			FROM event,organization
			WHERE event.org_id = organization.org_id
			AND event.event_id = ?
			ORDER BY event.date DESC",
			array( (int) $id )
		);
		return $myevent;
	}

	function getEvent($orgname)
	{

		$gevent = $this->db->getAll("SELECT event.name Event,
				event.date,
				event.starttime,
				event.endtime,
				event.fee,
				event.venue,
				organization.name Org,
				organization.logo logo,
				event.event_id,
				event.description
			FROM event,organization 
			WHERE event.org_id = organization.org_id AND
			organization.name = ?
			ORDER BY event.date DESC",
			array($orgname )
		);
		return $gevent;
	}

	function insertEvent( $org_id, $name, $date, $stime, $etime, $fee, $venue, $description )
	{
		$ievent= $this->db->execute("INSERT INTO event( 
			name, 
			date, 
			starttime,
			endtime,
			fee,
			venue,
			description,
			org_id
			) VALUES ( ?, ?, ?, ?, ?, ?, ?, ? )", 
			array( $name, $date, $stime, $etime, $fee, $venue, $description, (int) $org_id )
		);
		return $ievent;
	}

	function updateEvent( $event_id, $name, $date, $stime, $etime, $fee, $venue, $description ) 
	{
		$uevent = $this->db->execute("UPDATE event
			SET name = ?,
				date = ?,
				starttime = ?,
				endtime = ?,
				fee = ?,
				venue = ?,
				description = ?	
			WHERE event_id = ?",
			array( $name, $date,$stime,$etime, $fee, $venue, $description, (int) $event_id )
		);
		return $uevent;
	}
	
	function deleteEvent( $event_id ) {
		$this->db->execute(
			"DELETE FROM event
			WHERE event_id = ?",
			array( (int) $event_id )
		);
	}
	
	function countEvent( $org_id )
	{
		$cevent = $this->db->getAll("SELECT COUNT(*) FROM event",
			array( (int) $org_id )
		);
		return $cevent;
	}

}
	
	